// 存放接口
import request from '@/utils/request.js'
import store from '@/store/index.js'

export const allChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}
export const loginAPI = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

// 用户已登录接口
export const userChannelAPI = () => request({
  url: '/v1_0/user/channels',
  headers: {
    Authorization: 'Bearer ' + store.state.token
  }
})

// 获取文章列表接口
// export const articlesListAPI = ({ channelId }) => {
//   return request({
//     url: '/v1_0/articles',
//     params: {
//       channel_id: channelId,
//       timestamp: (new Date()).getTime()
//     }
//   })
// }
export const articlesListAPI = ({ channelId, timestamp }) => {
  return request({
    url: '/v1_0/articles',
    params: {
      channel_id: channelId,
      timestamp: timestamp || (new Date()).getTime()
    }
  })
}

// 文章 - 不感兴趣
export const articleDislikeAPI = ({ target }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: target
    },
    headers: {
      Authorization: 'Bearer ' + store.state.token
    }
  })
}

// 文章 - 举报
export const articleReportsAPI = ({ target, type, remark }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target: target,
      type: type,
      remark: remark
    },
    headers: {
      Authorization: 'Bearer ' + store.state.token
    }
  })
}

// 频道 - 更新已选
export const updateChannelAPI = ({ channels }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channels
    }
  })
}

// 搜索 - 联想菜单
export const suggestListAPI = ({ q }) => {
  return request({
    url: '/v1_0/suggestion',
    params: {
      q: q
    }
  })
}
